package code.bigmama.activity;

import code.bigmama.R;
import code.bigmama.controller.FileNameManager;
import code.bigmama.core.AudioRecorder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class RecordVoiceActivity extends Activity
{
	public static final String DEBUG_TAG = "recordVoiceActivity";
	
	private ToggleButton mRecordToogleButton  = null;
	private Button mSavingVoiceRecordingButton = null;
	private Button mCancle = null;
	
	private boolean isRecording = false;
	
	private AudioRecorder mAudioRecorder = null;
	
	@Override
    public void onCreate(Bundle savedInstanceState)
    {
        Log.d(DEBUG_TAG, "OnCreate()");
        setContentView(R.layout.add_audio);
        
        mRecordToogleButton = (ToggleButton) findViewById(R.id.AddAudio_TogleButtonREC);
        mSavingVoiceRecordingButton = (Button) findViewById(R.id.AddAudio_ButtonSave);
        mCancle = (Button) findViewById(R.id.AddAudio_ButtonCalcel);
        
        String fileName = FileNameManager.getInstance().getVoiceFileName();
        
        mAudioRecorder = new AudioRecorder("/sdcard/bigmama/"+fileName);
        
        setListener();
        
        super.onCreate(savedInstanceState);
    }
    
    private void setListener() 
    {
    	mRecordToogleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
			{
				isRecording  = isChecked;
				
				if(isChecked == true)
				{
					mAudioRecorder.record();
				}
				else if( isChecked == false)
				{
					mAudioRecorder.stop();
				}
			}
		});
	}

	@Override
    protected void onResume()
    {
        Log.d(DEBUG_TAG, "onResume()");
        super.onResume();
    }
	
	@Override
	protected void onStart()
	{
	    Log.d(DEBUG_TAG, "onStart()");
	    super.onStart();
	}
	
	@Override
	protected void onRestart()
	{
	    Log.d(DEBUG_TAG, "onRestart()");
	    super.onRestart();
	}
	
	@Override
	protected void onStop()
	{
	    Log.d(DEBUG_TAG, "onStop()");
	    super.onStop();
	}
	
	@Override
	protected void onDestroy()
	{
	    Log.d(DEBUG_TAG, "onDestroy()");
	    
	    super.onDestroy();
	}
}
